package com.antu.first.web.merchant;

import com.antu.first.bean.Hotel;
import com.antu.first.bean.Merchant;
import com.antu.first.bean.Room;
import com.antu.first.bean.RoomType;
import com.antu.first.service.RoomService;
import com.antu.first.service.RoomTypeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/5.  /roomTypeController/addRoomType
 */
@Controller
@RequestMapping("/roomTypeController")
public class RoomTypeController {
    @Autowired
    RoomTypeService roomTypeService;
    Map<String,Object> map;
    List<Room> list=new ArrayList();
    boolean flag;

    /**
     * 查询一个酒店的所有房间类型
     * @return
     */
    @RequestMapping(value = "/queryRoomTypeByHid")
    @ResponseBody
    public  Map<String,Object> queryRoomTypeByHid(HttpServletRequest httpServletRequest){
        map = new HashMap<String, Object>();
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        map=roomTypeService.queryRoomTypeByHid(merchant.getHotel().gethId());
        return map;
    }

    /**
     * 按照酒店ID和房间类型ID去修改房间类型
     * @param roomType
     * @return /roomTypeController/deleteRoomType
     */
    @RequestMapping(value = "/updateRoomTypeByRoomTypeId")
    @ResponseBody
    public Map<String,Object> updateRoomTypeByRoomTypeId(RoomType roomType,HttpServletRequest httpServletRequest){
        map = new HashMap<String, Object>();
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        roomType.setHotel(merchant.getHotel());
        return roomTypeService.updateRoomTypeByRoomTypeId(roomType);
    }

    /**
     * 按照酒店ID去添加房间类型
     * @param roomType
     * @return
     */
    @RequestMapping(value = "/addRoomType")
    @ResponseBody
    public Map<String,Object>  addRoomType(RoomType roomType,HttpServletRequest httpServletRequest){
        map = new HashMap<String, Object>();
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        roomType.setHotel(merchant.getHotel());
        map=roomTypeService.addRoomType(roomType);
        return map;
    }

    /**
     * 按照酒店ID和房间类型ｉｄ删除房间类型
     * @param roomType
     * @return
     */
    @RequestMapping(value = "/deleteRoomType")
    @ResponseBody
    public Map<String,Object> deleteRoomType(RoomType roomType,HttpServletRequest httpServletRequest){
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        roomType.setHotel(merchant.getHotel());
       return roomTypeService.deleteRoomType(roomType);
    }
}
